package com.AAL.DAO;

import java.util.List;

import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.ILogForPlanDAO;
import com.AAL.Model.City;
import com.AAL.Model.LogForPlan;
import com.AAL.Model.Plan;
import com.AAL.Utils.HibernateUtil;

public class LogForPlanDAO implements ILogForPlanDAO {

	@Override
	public LogForPlan saveAndUpdateLogForPlan(LogForPlan logForPlan) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		try {
			session.saveOrUpdate(logForPlan);
		} catch (Exception e) {
			return null;
		}
		session.getTransaction().commit();
		return logForPlan;
	}

	@Override
	public LogForPlan deleteLogForPlan(int logForPlanID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			session.beginTransaction();
			LogForPlan logForPlan = (LogForPlan) session.load(LogForPlan.class,
					logForPlanID);
			if (null != logForPlan) {
				session.delete(logForPlan);
			}
			session.getTransaction().commit();
			return logForPlan;
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			return null;
		}
	}

	@Override
	public LogForPlan getLogForPlan(int logForPlanID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		LogForPlan logForPlan = (LogForPlan) session.load(City.class,
				logForPlanID);
		return logForPlan;
	}

	@Override
	public List<LogForPlan> getLstLogForPlan(Plan plan) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public LogForPlan getLogForPlan(Plan plan, int time) {
		// TODO Auto-generated method stub
		return null;
	}

}
